/**
 * Customer.java
 * Develop a class with overloaded methods
 *   1. Create a class called Customer.java
 *
 *   2. Within the customer.java class, create a method called setCustomerInfo
 *      and add an overloaded method setCustomerInfo.
 *
 *   3. Depending on how the setCustomerInfo method is called, it does one of
 *      the following:
 *      a) Sets the ID, name, address and phone no. for a Customer object
 *         (this is the minimum info. Needed for a new Customer)
 *      b) Sets the ID, name, address, phone no., and email address for a
 *         Customer object.
 *
 * @author:  John Thomason
 *    Date:  Dec 6, 2008 / 8:13:11 AM
 *  Course:  CS222 - Java Programming II
 * Seminar:  5
 *  Assign:  2
 */


/**
 * Customer Class
 */
public class Customer {

//INSTANCE VARS
    
    private static Integer gid = 101;   //global identifier
    private Integer id;
    private String  name,
                    address,
                    phone,
                    email;


//CONSTRUCTORS

    private Customer(){} //No default Customer

    /**
     * Constructor with minimum property requirements
     *
     * @param id        The customer id (auto generated)
     * @param name      The customer's full name
     * @param address   The customer's mailing address
     * @param phone     The customer's phone number
     */
    public Customer(Integer id,
                    String  name,
                    String  address,
                    String  phone ){
        setCustomerInfo(id,name,address,phone);
    }
    /**
     * Constructor with all customer properties
     * 
     * @param id        The customer id (auto generated)
     * @param name      The customer's full name
     * @param address   The customer's mailing address
     * @param phone     The customer's phone number
     * @param email     The customer's email address
     */
    public Customer(Integer id,
                    String  name,
                    String  address,
                    String  phone,
                    String  email ){
        setCustomerInfo(id,name,address,phone,email);
    }//Customer Constructor

//GETTERS

    /**
     * getId()
     * Return this customer's identifier
     *
     * @return  The id of this customer
     */
    public Integer getId(){ return id; }

    /**
     * getName()
     * Return the customer's full name
     *
     * @return  The full name of this customer
     */
    public String getName(){ return name; }

    /**
     * getAddress()
     * Return the customer's mailing address
     *
     * @return  The mailing address of this customer
     */
    public String getAddress(){ return address; }

    /**
     * getPhone()
     * Return the customer's phone number
     *
     * @return  The phone number of this customer
     */
    public String getPhone(){ return phone; }

    /**
     * getEmail()
     * Return the customer's email address
     *
     * @return  The email address of this customer
     */
    public String getEmail(){
        if (this.email == null){ this.email = ""; }
        return this.email;
    }//getEmail()


//SETTERS

    /**
     * setId()
     * Store the customer id or generate a new id
     *
     * @param id    The attempted id
     */
    private void setId(Integer id){

        //if this customer does not have an id...
        if (this.id == null){

            //if the passed id is NOT valid...
            if (!id.equals(Customer.gid - 1)){

                //get a new ID
                id = Customer.newId();

            }//inner if
            this.id = id;

        }//outer if

    }//setId()

    /**
     * setName()
     * Store the customer's full name
     *
     * @param name  The full name of this customer
     */
    private void setName(String name){ this.name = name; }

    /**
     * setAddress()
     * Store the customer's mailing address
     *
     * @param address   The mailing address of this customer
     */
    private void setAddress(String address){ this.address = address; }

    /**
     * setPhone()
     * Store the customer's phone number
     *
     * @param phone The phone number of this customer
     */
    private void setPhone(String phone){ this.phone = phone; }

    /**
     * setEmail()
     * Store the customer's email address
     *
     * @param email The email address of this customer
     */
    private void setEmail(String email){ this.email = email; }


//OVERLOADED METHODS (REQUIRED)

    /**
     * setCustomerInfo()
     * Stores the available customer information in this object
     *
     * @param id        The customer id (auto generated)
     * @param name      The customer's full name
     * @param address   The customer's mailing address
     * @param phone     The customer's phone number
     */
    public void setCustomerInfo(Integer id,
                                String  name,
                                String  address,
                                String  phone ){
        setCustomerInfo(id,name,address,phone,"");
    }//setCustomerInfo()

    /**
     * setCustomerInfo()
     * Stores the available customer information in this object
     *
     * @param id        The customer id (auto generated)
     * @param name      The customer's full name
     * @param address   The customer's mailing address
     * @param phone     The customer's phone number
     * @param email     The customer's email address
     */
    public void setCustomerInfo(Integer id,
                                String  name,
                                String  address,
                                String  phone,
                                String  email ){
        setId(id);
        setName(name);
        setAddress(address);
        setPhone(phone);
        setEmail(email);
    }//setCustomerInfo()


//STATIC METHODS

    /**
     * newId()
     * Returns the next available global id, and increments
     *
     * @return  The next global id (gid)
     */
    public static Integer newId(){
        return gid++;
    }//newCustomerId()


//OVERRIDDEN METHODS

    /**
     * toString()
     * Return a string representing a customer object
     *
     * @return The customer information as a string
     */
    @Override
    public String toString(){
        return String.format("Customer:\n" +
                             "  CUST%05d -- %s\n" +
                             "  %s\n" +
                             "  %s\n" +
                             "  %s\n",
                             getId(),
                             getName(),
                             getAddress(),
                             getPhone(),
                             getEmail()
                            ); 
    }//toString()

}//end Customer class
